Sensor Fusion for Kinetis MCUs (ISSDK/KSDK version)
drivers.h File Reference
+ Include dependency graph for drivers.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SysTick Macros

The ARM SysTick counter is used to time various fusion options. Timings are then conveyed to the NXP Sensor Fusion Toolbox, where they are displayed for the developer. These functions should be portable to any ARM M0+, M3, M4 or M4F device. If you are using a different CPU architecture, you will need to provide an equivalent set of macros, remove the macro calls from the fusion routines, or define a set of empty macros.

void ARM_systick_enable (void)
 
void ARM_systick_start_ticks (int32_t *pstart)
 
int32_t ARM_systick_elapsed_ticks (int32_t start_ticks)
 
void ARM_systick_delay_ms (uint32_t iSystemCoreClock, uint32_t delay_ms)
 
Sensor Drivers

Each physical sensor must be provided with one initialization function and one "read" function. These must be installed by the user using the installSensor method defined in SensorFusionGlobals. By "physical sensor", we mean either individual sensor type (such as a 3-axis accelerometer) or a combo-sensor such as the NXP FXOS8700 6-axis accel plus mag. The init() function for each sensor is responsible for initializing all sensors contained in that package. The read() function is responsible for reading those same sensors and moving the results into the standard structures contained within the SensorFusionGlobals object.

int8_t MPL3115_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXOS8700_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXAS21002_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MMA8652_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXLS8952_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MAG3110_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MMA8451_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXLS8471Q_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MPL3115_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXOS8700_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXAS21002_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MMA8652_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXLS8952_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MAG3110_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MMA8451_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXLS8471Q_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MPL3115_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXOS8700_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXAS21002_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MMA8652_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXLS8952_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MAG3110_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t MMA8451_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXLS8471Q_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 

Detailed Description

Users who are not using NXP hardware will need to supply their own drivers in place of those defined here.

Definition in file drivers.h.

Function Documentation

void ARM_systick_delay_ms ( uint32_t  iSystemCoreClock,
uint32_t  delay_ms 
)

Definition at line 75 of file driver_systick.c.

Referenced by initializeFusionEngine().

76 {
77  int32 istart_ticks; // start ticks on entry
78  int32 ielapsed_ticks; // elapsed ticks
79  int16 i; // loop counter
80 
81  // loop for requested number of ms
82  for (i = 0; i < delay_ms; i++)
83  {
84  // loop until 1ms has elapsed
85  ARM_systick_start_ticks(&istart_ticks);
86  do
87  {
88  ielapsed_ticks = ARM_systick_elapsed_ticks(istart_ticks);
89  } while (ielapsed_ticks < iSystemCoreClock / 1000);
90  }
91 
92  return;
93 }
int32_t int32
Definition: sensor_fusion.h:57
int32 ARM_systick_elapsed_ticks(int32 start_ticks)
int16_t int16
Definition: sensor_fusion.h:56
void ARM_systick_start_ticks(int32 *pstart)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int32_t ARM_systick_elapsed_ticks ( int32_t  start_ticks)

Definition at line 64 of file driver_systick.c.

Referenced by ARM_systick_delay_ms(), and fFuseSensors().

65 {
66  int32 elapsed_ticks;
67 
68  // subtract the stored start ticks and check for wraparound down through zero
69  elapsed_ticks = start_ticks - (SYST_CVR & 0x00FFFFFF);
70  if (elapsed_ticks < 0) elapsed_ticks += SYST_RVR;
71 
72  return elapsed_ticks;
73 }
int32_t int32
Definition: sensor_fusion.h:57
#define SYST_RVR
#define SYST_CVR

+ Here is the caller graph for this function:

void ARM_systick_enable ( void  )

Definition at line 47 of file driver_systick.c.

Referenced by initializeFusionEngine().

48 {
49  SYST_CSR = 0x5u; // enable systick from internal clock
50  SYST_RVR = 0x00FFFFFFu; // set reload to maximum 24 bit value
51  return;
52 }
#define SYST_RVR
#define SYST_CSR

+ Here is the caller graph for this function:

void ARM_systick_start_ticks ( int32_t *  pstart)

Definition at line 55 of file driver_systick.c.

Referenced by ARM_systick_delay_ms(), and fFuseSensors().

56 {
57  // store the 24 bit systick timer
58  *pstart = SYST_CVR & 0x00FFFFFF;
59 
60  return;
61 }
#define SYST_CVR

+ Here is the caller graph for this function:

int8_t FXAS21002_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Referenced by fusion_task().

+ Here is the caller graph for this function:

int8_t FXAS21002_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Referenced by fusion_task(), and main().

+ Here is the caller graph for this function:

int8_t FXAS21002_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Referenced by main().

+ Here is the caller graph for this function:

int8_t FXLS8471Q_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 234 of file driver_FXLS8471Q.c.

235 {
236  int32_t status;
237  if(sensor->isInitialized == F_USING_ACCEL) {
238  if (sensor->addr == SPI_ADDR) {
239  status = Sensor_SPI_Write(sensor->bus_driver, &(sensor->slaveParams), FXLS8471Q_IDLE );
240  } else {
241  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, FXLS8471Q_IDLE );
242  }
243  sensor->isInitialized = 0;
244  sfg->Accel.isEnabled = false;
245  } else {
246  return SENSOR_ERROR_INIT;
247  }
248  return status;
249 }
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
spiSlaveSpecificParams_t slaveParams
SPI specific parameters. Not used for I2C.
#define SPI_ADDR
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
uint16_t addr
I2C address if applicable.
const registerwritelist_t FXLS8471Q_IDLE[]
int8_t FXLS8471Q_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 135 of file driver_FXLS8471Q.c.

136 {
137  GENERIC_DRIVER_GPIO *pGPIODriver = &Driver_GPIO_KSDK;
138  int32_t status;
139  uint8_t reg;
140  if (sensor->addr == SPI_ADDR) {
141  // Initialize the Slave Select Pin.
142  pGPIODriver->pin_init(&FXLS8471_SPI_CS, GPIO_DIRECTION_OUT, NULL, NULL, NULL);
143  // Initialize SPI parameters used by ISSDK SPI routines
144  sensor->slaveParams.pReadPreprocessFN = FXLS8471Q_SPI_ReadPreprocess;
145  sensor->slaveParams.pWritePreprocessFN = FXLS8471Q_SPI_WritePreprocess;
146  sensor->slaveParams.pTargetSlavePinID = &FXLS8471_SPI_CS;
147  sensor->slaveParams.spiCmdLen = FXLS8471Q_SPI_CMD_LEN;
148  sensor->slaveParams.ssActiveValue = FXLS8471Q_SS_ACTIVE_VALUE;
149  // Read the WhoAmI
150  status = Register_SPI_Read(sensor->bus_driver, &(sensor->slaveParams), FXLS8471Q_WHO_AM_I, 1, &reg);
151  } else {
152  status = Register_I2C_Read(sensor->bus_driver, sensor->addr, FXLS8471Q_WHO_AM_I, 1, &reg);
153  }
154  if (status==SENSOR_ERROR_NONE) {
155  sfg->Accel.iWhoAmI = reg;
156  if (reg!=FXLS8471Q_WHO_AM_I_WHOAMI_VALUE) return(SENSOR_ERROR_INIT);
157  } else {
158  return(status);
159  }
160 
161  // Configure and start the FXLS8471Q sensor. This does multiple register writes
162  if (sensor->addr == SPI_ADDR)
163  status = Sensor_SPI_Write(sensor->bus_driver, &(sensor->slaveParams), FXLS8471Q_Initialization );
164  else
165  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, FXLS8471Q_Initialization );
166 
167  // Stash some needed constants in the SF data structure for this sensor
168  sfg->Accel.iCountsPerg = FXLS8471Q_COUNTSPERG;
169  sfg->Accel.fgPerCount = 1.0F / FXLS8471Q_COUNTSPERG;
170 
171  sensor->isInitialized = F_USING_ACCEL;
172  sfg->Accel.isEnabled = true;
173 
174  return (status);
175 }
#define FXLS8471Q_COUNTSPERG
const registerwritelist_t FXLS8471Q_Initialization[]
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
spiSlaveSpecificParams_t slaveParams
SPI specific parameters. Not used for I2C.
#define SPI_ADDR
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
uint16_t addr
I2C address if applicable.
int8_t FXLS8471Q_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 177 of file driver_FXLS8471Q.c.

178 {
179  uint8_t Data_Buffer[6 * FXLS8471Q_ACCEL_FIFO_SIZE]; // I2C read buffer
180  int8_t status=0; // I2C transaction status
181  int8_t j; // scratch
182  uint16_t sensor_fifo_count = 1;
183  int16_t sample[3];
184 
185  if(sensor->isInitialized != F_USING_ACCEL)
186  {
187  return SENSOR_ERROR_INIT;
188  }
189 
190  // read the F_STATUS register (mapped to STATUS) and extract number of measurements available (lower 6 bits)
191  if (sensor->addr == SPI_ADDR)
192  status = Sensor_SPI_Read(sensor->bus_driver, &(sensor->slaveParams), FXLS8471Q_F_STATUS_READ, Data_Buffer );
193  else
194  status = Sensor_I2C_Read(sensor->bus_driver, sensor->addr, FXLS8471Q_F_STATUS_READ, Data_Buffer );
195 
196  sensor_fifo_count = Data_Buffer[0] & 0x3F;
197  if (status==SENSOR_ERROR_NONE) {
198  // return if there are no measurements in the sensor FIFO.
199  // this will only occur when the FAST_LOOP_HZ equals or exceeds ACCEL_ODR_HZ
200  if (sensor_fifo_count == 0) return SENSOR_ERROR_READ;
201  } else {
202  return(status);
203  }
204 
205  FXLS8471Q_DATA_READ->numBytes = 6 * sensor_fifo_count;
206  if (sensor->addr == SPI_ADDR)
207  status = Sensor_SPI_Read(sensor->bus_driver, &sensor->slaveParams, FXLS8471Q_DATA_READ, &(Data_Buffer[0]) );
208  else
209  status = Sensor_I2C_Read(sensor->bus_driver, sensor->addr, FXLS8471Q_DATA_READ, &(Data_Buffer[0]) );
210 
211  if (status==SENSOR_ERROR_NONE) {
212  for (j=0; j<sensor_fifo_count; j++) {
213  sample[CHX] = (Data_Buffer[6*j ] << 8) | Data_Buffer[6*j + 1] ;
214  sample[CHY] = (Data_Buffer[6*j + 2] << 8) | Data_Buffer[6*j + 3] ;
215  sample[CHZ] = (Data_Buffer[6*j + 4] << 8) | Data_Buffer[6*j + 5] ;
216  conditionSample(sample); // truncate negative values to -32767
217  addToFifo((FifoSensor*) &(sfg->Accel), ACCEL_FIFO_SIZE, sample);
218  }
219  }
220 
221  return (status);
222 }
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
void addToFifo(FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
#define ACCEL_FIFO_SIZE
FXOS8700 (accel), MMA8652, FXLS8952 all have 32 element FIFO.
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
#define FXLS8471Q_ACCEL_FIFO_SIZE
#define CHZ
spiSlaveSpecificParams_t slaveParams
SPI specific parameters. Not used for I2C.
#define SPI_ADDR
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two&#39;s complement value for a 16-...
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
const registerreadlist_t FXLS8471Q_F_STATUS_READ[]
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
uint16_t addr
I2C address if applicable.
registerreadlist_t FXLS8471Q_DATA_READ[]

+ Here is the call graph for this function:

int8_t FXLS8952_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)
int8_t FXLS8952_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Referenced by main().

+ Here is the caller graph for this function:

int8_t FXLS8952_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Referenced by main().

+ Here is the caller graph for this function:

int8_t FXOS8700_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 296 of file driver_FXOS8700.c.

297 {
298  int32_t status;
299  if(sensor->isInitialized == (F_USING_ACCEL|F_USING_MAG)) {
300  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, FXOS8700_FULL_IDLE );
301  sensor->isInitialized = 0;
302 #if F_USING_ACCEL
303  sfg->Accel.isEnabled = false;
304 #endif
305 #if F_USING_MAG
306  sfg->Mag.isEnabled = false;
307 #endif
308  } else {
309  return SENSOR_ERROR_INIT;
310  }
311  return status;
312 }
const registerwritelist_t FXOS8700_FULL_IDLE[]
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
MagSensor Mag
magnetometer storage
bool isEnabled
true if the device is sampling
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38
int8_t FXOS8700_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 151 of file driver_FXOS8700.c.

Referenced by main().

152 {
153  int32_t status;
154  uint8_t reg;
155  status = Register_I2C_Read(sensor->bus_driver, sensor->addr, FXOS8700_WHO_AM_I, 1, &reg);
156 
157  if (status==SENSOR_ERROR_NONE) {
158 #if F_USING_ACCEL
159  sfg->Accel.iWhoAmI = reg;
160  sfg->Accel.iCountsPerg = FXOS8700_COUNTSPERG;
161  sfg->Accel.fgPerCount = 1.0F / FXOS8700_COUNTSPERG;
162 #endif
163 #if F_USING_MAG
164  sfg->Mag.iWhoAmI = reg;
166  sfg->Mag.fCountsPeruT = (float) FXOS8700_COUNTSPERUT;
167  sfg->Mag.fuTPerCount = 1.0F / FXOS8700_COUNTSPERUT;
168 #endif
169  if (reg != FXOS8700_WHO_AM_I_PROD_VALUE) {
170  return SENSOR_ERROR_INIT; // The whoAmI did not match
171  }
172  } else {
173  // whoAmI will rettain default value of zero
174  // return with error
175  return status;
176  }
177 
178  // Configure and start the fxos8700 sensor. This does multiple register writes
179  // (see FXOS8700_Initialization definition above)
180  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, FXOS8700_Initialization );
182 #if F_USING_ACCEL
183  sfg->Accel.isEnabled = true;
184 #endif
185 #if F_USING_MAG
186  sfg->Mag.isEnabled = true;
187 #endif
188 
189  return (status);
190 }
#define FXOS8700_COUNTSPERUT
#define FXOS8700_COUNTSPERG
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
int16_t iCountsPeruT
counts per uT
MagSensor Mag
magnetometer storage
float fuTPerCount
uT per count
bool isEnabled
true if the device is sampling
const registerwritelist_t FXOS8700_Initialization[]
float fCountsPeruT
counts per uT
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
uint8_t iWhoAmI
sensor whoami
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t FXOS8700_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 265 of file driver_FXOS8700.c.

Referenced by main().

266 {
267  int8_t sts1 = 0;
268  int8_t sts2 = 0;
269 #if F_USING_ACCEL
270  sts1 = FXOS8700_ReadAccData(sensor, sfg);
271 #endif
272 
273 #if F_USING_MAG
274  sts2 = FXOS8700_ReadMagData(sensor, sfg);
275 #endif
276 
277  if (sts1)
278  return (sts1);
279  else
280  return (sts2);
281 }
int8_t FXOS8700_ReadMagData(PhysicalSensor *sensor, SensorFusionGlobals *sfg)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t MAG3110_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 168 of file driver_MAG3110.c.

Referenced by fusion_task().

169 {
170  int32_t status;
171  if(sensor->isInitialized == F_USING_MAG) {
172  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, MAG3110_IDLE );
173  sensor->isInitialized = 0;
174  sfg->Mag.isEnabled = false;
175  } else {
176  return SENSOR_ERROR_INIT;
177  }
178  return status;
179 }
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
MagSensor Mag
magnetometer storage
const registerwritelist_t MAG3110_IDLE[]
bool isEnabled
true if the device is sampling
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38

+ Here is the caller graph for this function:

int8_t MAG3110_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 103 of file driver_MAG3110.c.

Referenced by fusion_task(), and main().

104 {
105  int32_t status;
106  uint8_t reg;
107  status = Register_I2C_Read(sensor->bus_driver, sensor->addr, MAG3110_WHO_AM_I, 1, &reg);
108  if (status==SENSOR_ERROR_NONE) {
109  sfg->Mag.iWhoAmI = reg;
110  if (reg!=MAG3110_WHOAMI_VALUE) {
111  return(SENSOR_ERROR_INIT);
112  }
113  } else {
114  // iWhoAmI will return default value of zero
115  // return with error
116  return(SENSOR_ERROR_INIT);
117  }
118 
119  // Configure and start the MAG3110 sensor. This does multiple register writes
120  // (see MAG3110_Initialization definition above)
121  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, MAG3110_Initialization );
122 
123  // Stash some needed constants in the SF data structure for this sensor
125  sfg->Mag.fCountsPeruT = (float)MAG3110_COUNTSPERUT; // IAR optimized this out without the #pragma before the function
126  sfg->Mag.fuTPerCount = 1.0F / MAG3110_COUNTSPERUT; // IAR optimized this out without the #pragma before the function
127 
128  sensor->isInitialized = F_USING_MAG; // IAR optimized this out without the #pragma before the function
129  sfg->Mag.isEnabled = true; // IAR optimized this out without the #pragma before the function
130 
131  return (status);
132 }
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
int16_t iCountsPeruT
counts per uT
MagSensor Mag
magnetometer storage
float fuTPerCount
uT per count
bool isEnabled
true if the device is sampling
float fCountsPeruT
counts per uT
const registerwritelist_t MAG3110_Initialization[]
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
#define MAG3110_COUNTSPERUT
uint8_t iWhoAmI
sensor whoami
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38

+ Here is the caller graph for this function:

int8_t MAG3110_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 134 of file driver_MAG3110.c.

Referenced by main().

135 {
136  uint8_t I2C_Buffer[6]; // I2C read buffer
137  int8_t status; // I2C transaction status
138  int16_t sample[3]; // Reconstructed sample
139 
140  if(sensor->isInitialized != F_USING_MAG)
141  {
142  return SENSOR_ERROR_INIT;
143  }
144 
145  status = Sensor_I2C_Read(sensor->bus_driver, sensor->addr, MAG3110_DATA_READ, I2C_Buffer );
146  sample[CHX] = (I2C_Buffer[0] << 8) | I2C_Buffer[1];
147  sample[CHY] = (I2C_Buffer[2] << 8) | I2C_Buffer[3];
148  sample[CHZ] = (I2C_Buffer[4] << 8) | I2C_Buffer[5];
149  if (status==SENSOR_ERROR_NONE) {
150  conditionSample(sample); // truncate negative values to -32767
151  sample[CHZ] = -sample[CHZ]; // +Z should point up (MAG3110 Z positive is down)
152  addToFifo((FifoSensor*) &(sfg->Mag), MAG_FIFO_SIZE, sample);
153  }
154 
155  return (status);
156 }
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
void addToFifo(FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
#define MAG_FIFO_SIZE
FXOS8700 (mag), MAG3110 have no FIFO so equivalent to 1 element FIFO.
MagSensor Mag
magnetometer storage
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
#define CHZ
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two&#39;s complement value for a 16-...
registerreadlist_t MAG3110_DATA_READ[]
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t MMA8451_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)
int8_t MMA8451_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)
int8_t MMA8451_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)
int8_t MMA8652_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)
int8_t MMA8652_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)
int8_t MMA8652_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)
int8_t MPL3115_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)
int8_t MPL3115_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Referenced by main().

+ Here is the caller graph for this function:

int8_t MPL3115_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Referenced by main().

+ Here is the caller graph for this function: